import request from '../utils/request'

export function getUsersListApi ({ query, pagenum, pagesize }) {
  return request({
    method: 'get',
    url: 'users',
    params: {
      query,
      pagenum,
      pagesize
    }
  })
}

export function changeUserStateApi (uId, type) {
  return request({
    method: 'put',
    url: `users/${uId}/state/${type}`
  })
}

export function addUserApi ({ username, password, email, mobile }) {
  return request({
    method: 'post',
    url: 'users',
    data: {
      username,
      password,
      email,
      mobile
    }
  })
}

export function getUserByIdApi (id) {
  return request.get(`users/${id}`)
}

export function editUserByIdApi (id, email, mobile) {
  return request({
    method: 'put',
    url: 'users/' + id,
    data: {
      email,
      mobile
    }
  })
}

export const removeUserByIdApi = (id) => {
  return request({
    method: 'delete',
    url: 'users/' + id
  })
}

export function allotUsersRoleApi (id, rid) {
  return request({
    method: 'put',
    url: `users/${id}/role`,
    data: {
      rid
    }
  })
}
